const actions = {
  playerMove({ commit }, keycode) {
    commit("playerMove", keycode);
  },
  addInventory({ commit }, obj) {
    commit("addInventory", obj);
  },
};

const mutations = {
  playerMove(state, keycode) {
    let direction;
    switch (keycode) {
      case 87:
        state.player.y -= 1;
        direction = "top";
        break;
      case 83:
        state.player.y += 1;
        direction = "bottom";
        break;
      case 65:
        state.player.x -= 1;
        direction = "left";
        break;
      case 68:
        state.player.x += 1;
        direction = "right";
        break;
    }
    state.player.direction = direction;
  },
  addInventory(state, { id, count }) {
    state.player.inventory.push({
      id,
      count,
    });
  },
};

const state = {
  player: {
    x: 0,
    y: 0,
    direction: "right",
    inventory: [],
    currentInventoryIndex: 1,
    showBag: false,
    speed: 20, // 速度每秒移动几个方块
    attacking: false,
    pointAngle: 0,
  },
  mapSeed: "hello world",
  mapSeedScale: 0.005,
  mapTime: 360, // 地图时间 单位分钟
  system: {
    areaBlockDiameter: 5, // 区块直径
    areaBlockRenderDistance: 5, // 区块渲染距离
    areaBlockHideDistance: 5, // 区块最大显示距离
    areaBlockLoadAnimation: false, // 区块加载动画 比较消耗性能!
    visualLevel: 1, // 可视等级
    blockAnimation: false, // 方块静态动画 非常消耗性能!
  },
};

export default {
  namespaced: true,
  actions,
  mutations,
  state,
};
